package by.averianov.discounta.services.impl;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.persistence.metamodel.SingularAttribute;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.averianov.discounta.dataaccess.ProductDao;
import by.averianov.discounta.datamodel.Product;
import by.averianov.discounta.services.SaleService;

@Service
public class SaleServiceImpl implements SaleService {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(SaleServiceImpl.class);

	@PostConstruct
	private void init() {
		// this method will be called by Spring after bean instantiation. 
		// Can be used for any initialization process.
		LOGGER.info("Instance of SaleService is created. Class is: {}", getClass().getName());
	}
	
	@Inject
	protected ProductDao productDao;

	@Override
    public  List<Product> getAllProductNotNull(SingularAttribute<Product, ?> attr, boolean ascending, int startRecord, int pageSize) {
		return productDao.getAllNotNull(attr, ascending, startRecord, pageSize);
	}

	@Override
    public Long getCountProductNotNull() {
		return productDao.getCountNotNull();
	}

	@Override
    public Product getProductById(Long id) {
		return productDao.getById(id);
	}
	
}
